/*
 *    beep.c  -  beep api & driver
 *
 *	  Board:		akae2440
 *    environment:	bootloader & ADS
 *    Author:		akaedu
 *    Date:			2009-5-26
 *    web:			www.akaedu.org
 *
 *  
 *	  GPIO address_MAP
 *	  
 *	  CPLD_MAP_BASE	physical address is	0x20800000		
 *	  CPLD_LED		physical address is	0x20800000		
 *	  CPLD_SEG		physical address is	0x20800080
 *	  CPLD_DIP		physical address is	0x208000a0
 *
 *	  GPIO port_MAP   
 *	  
 *	  GPA_PORT~GPB_PORT(130 multi-functional input port pins)
 *	  GPIO_BASE	:	GPACON	:	0x56000000	
 *	  
 *	  NAME			GPIO		CPLD_IN		CPLD_OUT	GPIO_CON		MODE_bit_CON	GPIO_DAT		MODE_bit_DAT		
 *	  BEEP			GPB0		TOUT0		BEEP		0x56000010		[1:0]			0x56000014		[0]
 *
 *	  GPIO key_scn_MAP
 *
 *	  NAME			PORT_OUT			PORT_IN			
 *	  KEY(sw1)		KBOUT1 : GPB8		KBIN1 : ENT0 : GPF0				
 *	  KEY(sw2)		KBOUT0 : GPB9		KBIN1 : ENT0 : GPF0			
 *	  KEY(sw3)		KBOUT1 : GPB8		KBIN0 : ENT2 : GPF2				
 *	  KEY(sw4)		KBOUT1 : GPB8		KBIN1 : ENT2 : GPF2				
 *
 *	  GPIO_CON						GPIO_DAT				GPIO		MODE_bit_CON		MODE_bit_DAT
 *	  GPBCON : 0x56000010			GPBDAT : 0x56000014		GPB8		[17:16]				[8]			
 *	  GPBCON : 0x56000010			GPBDAT : 0x56000014		GPB9		[19:18]				[9]			
 *	  GPFCON : 0x56000050			GPBDAT : 0x56000054		GPF0		[1:0]				[0]			
 *	  GPFCON : 0x56000050			GPBDAT : 0x56000054		GPF2		[5:4]				[2]			
 *
 */
#include "beep.h"


#define  GPBCON			*((volatile unsigned int *)0x56000010)        
#define  GPBDAT			*((volatile unsigned int *)0x56000014)        


int beep_init(void)
{
	
	/* configure GPB0 : TOUT0 : BEEP output */
	GPBCON &= ~(1<<1);
	GPBCON |= 1<<0;

	return 0;
}

int beep_on(void)
{
	GPBDAT |= 1<<0;
	
	return 0;
}

int beep_off(void)
{
	GPBDAT &= ~(1<<0);
	
	return 0;
}

static void delay(int time)
{
	int i,j;
	
	for (i = 0; i < time; i++)
		for (j = 0; j < 60000000; j++)
		;
}

int beep_test(void)
{
	
	while(1)
	{
		beep_on();
		delay(1);
		beep_off();
		delay(1);
	}

	return 0;
}